/**
 * Draggee
 *
 * @author		Allen Chou
* @version		1.0.2 (last update: Aug 7 2008)
 * @link		http://cjcat2266.deviantart.com
 */

package idv.cjcat.utils.dragger {
	import flash.display.DisplayObject;
	import flash.events.EventDispatcher;
	import flash.errors.IllegalOperationError;
	
	import idv.cjcat.geom.Vector2;
	
	public class Draggee extends EventDispatcher {
		
		public var obj:Object;
		public var property:String;
		public var factor:Number;
		public var active:Boolean = true;
		
		private var _useAngle:Boolean = false;
		
		internal var _value:Number;
		
		internal var _min:Number;
		internal var _max:Number;
		
		public function Draggee(obj:Object, property:String, factor:Number = 1, min:Number = NaN, max:Number = NaN) {
			this.obj = obj;
			this.property = property;
			this.factor = factor;
			this._value = obj[property];
			
			if (isNaN(min)) {
				_min = -Number.MAX_VALUE;
			} else {
				_min = min;
			}
			if (isNaN(max)) {
				_max = Number.MAX_VALUE;
			} else {
				_max = max;
			}
		}
		
		public function get min():Number { return _min; }
		public function set min(value:Number):void {
			_min = value;
			if (_min > _max) _max = _min;
		}
		
		public function get max():Number { return _max; }
		public function set max(value:Number):void {
			_max = value;
			if (_max < _min) _min = _max;
		}
		
		public function get useAngle():Boolean { return _useAngle; }
		public function set useAngle(value:Boolean):void {
			if (!(obj is DisplayObject) && (value == true)) throw new IllegalOperationError("The obj property must be a DisplayObject in order to set the useAngle property to true.");
			_useAngle = value;
		}
		
		public function get value():Number { return _value; }
	}
}